//
//  FJBlackListViewController.swift
//  FruitJuice
//
//  Created by Rui on 2023/12/16.
//

import UIKit

class FJBlackListViewController: FJBaseViewController {

    private let backButton          = c_make_ex(UIButton.self)
        .image("FJ_Profile_back").end()
    private let titleLabel          = c_make_ex(UILabel.self)
        .text("Blocklist").color(.black).font(19.font_bold).end()
    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.backgroundColor = .clear
        tableView.tableFooterView = UIView(frame: .zero)
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.rowHeight = 85
        tableView.register(FJBlackTableViewCell.self)

        return tableView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        navigation.bar.isHidden = true
        view.subviews{
            backButton
            titleLabel
            tableView
        }
        
        backButton.top(.statusHeight + 7).leading(15).size(30)
        titleLabel.leading(60)
        titleLabel.CenterY == backButton.CenterY
        tableView.leading(0).trailing(0).bottom(.safe_bottom)
        tableView.Top == backButton.Bottom + 7
        
        backButton.addTarget(self, action: #selector(clickBackButton), for: .touchUpInside)
    }
    
    @objc private func clickBackButton(){
        self.navigationController?.popViewController(animated: true)
    }

}

extension FJBlackListViewController: UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        itemInfos.count
        return 10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.cell(FJBlackTableViewCell.self, indexPath: indexPath)
//        cell.itemType = itemInfos[indexPath.row]
        return cell
    }
//    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//
//        tableView.deselectRow(at: indexPath, animated: true)
//        switch itemInfos[indexPath.row]{
//        case .delete:
//            let deleteV = LearningDeleteAccountView()
//            saAnimate.animation(show: deleteV)
//            break
//        case .erms:
//            let webVC = LearningWebViewController()
//            webVC.titleText = "Terms of use"
//            webVC.webUrl = URLTool.technicalSupportUrl
//            self.navigationController?.pushViewController(webVC, animated: true)
//            break
//        case .privacy:
//            let webVC = LearningWebViewController()
//            webVC.titleText = "Privacy Policy"
//            webVC.webUrl = URLTool.privacyPolicyUrl
//            self.navigationController?.pushViewController(webVC, animated: true)
//            break
//        case .cache:
//            let clearView = LearningClearCacheView()
//            clearView.didCleanCompletion = { [weak self] in
//                self?.tableView.reloadData()
//            }
//            saAnimate.animation(show: clearView)
//            break
//        default:
//            return
//        }
//
//    }
}

class FJBlackTableViewCell: UITableViewCell {
    
    private let backView            = c_make_ex(UIView.self)
        .bgColor("#EFEFEF").corner(35).end()
    private let iconImageView       = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).corner(25).end()
    private let nameLabel           = c_make_ex(UILabel.self)
        .color(.black).font(16.font_bold).end()
    private let contentLabel        = c_make_ex(UILabel.self)
        .color(.black).font(14.font_regular).end()
    private let removeButton        = c_make_ex(UIButton.self)
        .bgColor("#FC9C05").corner(20).color(.white)
        .text("Remove").font(17.font_bold).end()
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.subviews {
            backView.subviews{
                iconImageView
                nameLabel
                contentLabel
                removeButton
            }
        }
        backView.leading(15).trailing(15).top(15).bottom(0)
        iconImageView.leading(10).size(50).centerVertically()
        nameLabel.leading(70).trailing(120).top(15)
        contentLabel.trailing(120).leading(70)
        contentLabel.Top == nameLabel.Bottom + 3
        removeButton.width(100).trailing(10).height(40).centerVertically()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
